﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace CsvSerializer
{
    /// <summary>
    /// Defines methods used to write to a CSV file.
    /// </summary>
    public interface ICsvWriter : IDisposable
    {
        /// <summary>
        /// Gets or sets the delimiter used to
        /// separate the fields of the CSV records.
        /// </summary>
        char Delimiter { get; }

        /// <summary>
        /// Gets the date format
        /// </summary>
        string DateFormat { get; }

        /// <summary>
        /// Gets are sets a value indicating if the
        /// CSV file has a header record.
        /// </summary>
        bool HasHeaderRecord { get; }

        /// <summary>
        /// Gets the binding flags used to get the properties
        /// from the the custom class object.
        /// </summary>
        BindingFlags PropertyBindingFlags { get; }

        /// <summary>
        /// Writes the field to the CSV file.
        /// When all fields are written for a record,
        /// <see cref="NextRecord()" /> must be called
        /// to complete writing of the current record.
        /// </summary>
        /// <param name="field">The field to write.</param>
        void WriteField(string field);

        /// <summary>
        /// Writes the field to the CSV file.
        /// When all fields are written for a record,
        /// <see cref="NextRecord()" /> must be called
        /// to complete writing of the current record.
        /// </summary>
        /// <typeparam name="T">The type of the field.</typeparam>
        /// <param name="field">The field to write.</param>
        void WriteField<T>(T field);

        /// <summary>
        /// Ends writing of the current record
        /// and starts a new record. This is used
        /// when manually writing records with <see cref="WriteField{T}( T )"/>
        /// </summary>
        void NextRecord();

        /// <summary>
        /// Writes the record to the CSV file.
        /// </summary>
        /// <typeparam name="T">The type of the record.</typeparam>
        /// <param name="record">The record to write.</param>
        void WriteRecord<T>(T record);

        /// <summary>
        /// Writes the list of records to the CSV file.
        /// </summary>
        /// <typeparam name="T">The type of the record.</typeparam>
        /// <param name="records">The list of records to write.</param>
        void WriteRecords<T>(IEnumerable<T> records);
    }
}